Fixes + check for dupes contexts in postgres/redshift #139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description & motivation
@agnessnowplow Raised an issue around when the session/user identifiers have the same context it fails on PG/RS (due to duplicate CTEs with the same name). This is actually a wider issue, it would fail with the same context used multiple times in one of the identifiers, and also if you use the context as an identifier then add it in the
entity_or_sde
as well. Giving each CTE a custom name felt complicated, so I have instead made the logic directly on the base macros.Basically, I have got a distinct list of contexts that need CTEing and joining, and where there are duplicates it uses the alias and prefix of the FIRST instance, but the FIELD of the actual record (please double check I haven't misses this anywhere). I do not raise a warning in the manifest because they should never need to access the inner workings of this code so we can just manage it for them.
I also made a few other tweaks while I was here.
We should probably add some tests for this, but that felt like a large task that we may not have time to do before release
Checklist